<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<script>
    // 多个if
    const condition = ['0x00', '0x03', '0x10', '0x13']
    if (condition.includes('0x00')) {
        console.log('异常')
    }

    // 声明多个变量
    const [a, b, c] = [10, 20, 30]
    console.log(a, b, c)

    // 空值检查  判断 不为undefined/null/''
    let test = '123';
    let test2 = test || ''

    // 双??符号  代替三目
    let test3 = test ?? 'default';
     let test4 = null ?? 'aa';
    console.log(test3)
    console.log(test4)

    //多个条件 的&&操作符
    let test5 = true

    function calc() {
        console.log('calc')
    }

    function calc2() {
        console.log('calc2')
    }

    function calc3() {
        console.log('calc3')
    }

    if (test5) {
        calc()
    }
    // 可优化成
    test5 && calc();
    // switch 执行优化
    let k = 2
    switch (k) {
        case 1: {
            calc();
            break;
        }
        case 2: {
            calc2();
            break;
        }
        case 3: {
            calc3();
            break;
        }
    }

    // 写成
    let d = {
        1: calc,
        2: calc2,
        3: calc3
    }
    d[k] && d[k]()

    // 箭头函数隐式返回 不需要用return
    let calculate = d => (Math.PI)
    console.log(calculate)

    // 默认参数法
    function add(a, b) {
        if (a === undefined) {
            a = 1
        }
        if (b === undefined) {
            b = 1
        }
        return a + b
    }

    // 可优化成
    add = (x = 5, y = 10) => (x + y);
    console.log(add()) // 不传递参数，计算默认值
</script>
</body>

</html>
